Repository navigation
fix(instagram): request the saved feed like the web app, never retry "fail" answers - #4
Open
Pacman1984 wants to merge 4 commits into
Open
Pacman1984 wants to merge 4 commits into
Pacman1984 wants to merge 4 commits into
Conversation
…"fail" answers With a web session, the private-API saved feed on i.instagram.com (iPad headers) was answered with 200 "fail" "We're sorry, but something went wrong" and instaloader retried it three times. The feed is now requested the way the Instagram web app (and gallery-dl's REST client) does it: GET https://www.instagram.com/api/v1/feed/saved/posts/ with X-IG-App-ID, X-CSRFToken from the csrftoken cookie, X-Requested-With, X-ASBD-ID, X-IG-WWW-Claim, Sec-Fetch-* and the saved page as Referer, on a temporary copy of instaloader's session (cookies, rate controller, error handling). - New option instagram.feed_api = "web" | "iphone" (default "web"); invalid values fail with a clear message and in `config validate`. - Feed pages get a single attempt; only network errors are retried up to max_connection_attempts. A "fail" answer raises the new InstagramFeedUnavailable (RateLimited subclass): exit code 3, report stopped_reason and job error_code "feed_unavailable", message says the session is fine, nothing was lost and which feed_api to try. - The session outcome is reported through the progress callback and printed by the CLI ("Instagram session verified (no password login)" or a warning before every password login, with the reason). - Docs (operations, configuration, CLI/API references), changelog and config.example.toml updated; tests cover both APIs with fakes and with a real InstaloaderContext over a faked HTTP layer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…stagram's reason A scripted password login right after a session check made Instagram flag the account (confirmation request / login redirect on the first saved-feed page). Automatic password logins are now switched off: - InstagramCollector gets allow_password_login (default False). Without a usable session (no session file, unreadable file, session logged out) it raises InstagramAuthRequired (exit code 2) that says no password login was attempted, why, and to run `postparse check instagram --login` in a terminal. The session file is not touched. - Only `check instagram --login` passes allow_password_login=True and prints a warning before the password login. ExtractionService (CLI extract, API jobs) and TranscriptionService re-fetches force it to False, even if overrides try to enable it. - Logged-out sessions, confirmations, feed refusals and rate limits quote Instagram's sanitized short reason (message "...", or a login redirect as scheme://host/path); no query strings, cookies, tokens or bodies, at most 200 characters. A failed session check no longer quotes the request URL. - Rate-limit markers are no longer matched inside URLs or request paths, so a "fail" answer whose cursor contains 429 is feed_unavailable; HTTP 429 / TooManyRequestsException is still a rate limit. Docs (operations, CLI/API reference, configuration) and CHANGELOG updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… browser session instaloader's password login (4.15.5) seeds a fresh cookie jar with empty placeholder cookies (sessionid, ds_user_id, csrftoken, ...) and reports success as soon as Instagram answers "authenticated: true", even when no real sessionid cookie came back (instaloader issue #2487). `check instagram --login` then said "session is valid" and saved a session file without login cookies, which the next extract rejected. - After the password login (and the 2FA code) the placeholders are removed, a session without sessionid / numeric ds_user_id raises InstagramAuthRequired without a request, and the new session is verified with one session check before it is saved. Nothing is saved on any failure. - New `postparse check instagram --import-session`: reads the sessionid cookie of the logged-in browser from a hidden prompt (csrftoken optional, generated when empty), normalizes it, verifies it with exactly one request and saves it only when Instagram confirms the session of INSTAGRAM_USERNAME (InstagramCollector.import_session). Never uses the password. - With feed_api = "web" the session check now asks www.instagram.com with the same web headers as the saved feed (one shared web client), so a browser session is never sent with iPad headers to i.instagram.com. - Messages and docs recommend --import-session first, --login as the alternative; cookie values in JSON or as bare values are redacted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd reuse it With instagram.feed_api = "web" the session check asked www.instagram.com/api/v1/users/<ds_user_id>/info/. The Instagram web app does not normally call that endpoint, and a fresh --import-session (its only request, about 22 hours after the previous one) was answered there with 429 Too Many Requests. The web check now requests the first page of the saved feed (api/v1/feed/saved/posts/), exactly as the feed walk does and as the web app does when the saved page is opened: same _WebClient and headers, the saved page as Referer, a single connection attempt. Logged out, checkpoint and throttle answers map as before; a 200 answer with "status": "fail" raises InstagramFeedUnavailable instead of being taken for a logout. Nothing is saved on any failure. The feed does not name the viewer, so in web mode the account is the one the sessionid belongs to; feed_api = "iphone" keeps the user-info check and the username comparison. The unused web user-info path is gone. The checked page is kept on the collector (tied to the loader's current session, used once) and the default saved-feed walk starts with it, so page 1 is never requested twice: an import is one request, and extract instagram --limit 1 --stop-after-known 1 with a valid session is exactly one request in web mode. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Live test after #3 (2026-10-26 22:02): the new session check passed (session valid, no 401, no password login), but the saved feed on the private API
i.instagram.com/api/v1/feed/saved/posts/answered200 OK - "fail" status, "We're sorry, but something went wrong."(instaloader retried it 3×).The session is a web session, so the feed is now requested the way the Instagram web app (and gallery-dl's
InstagramRestAPI) do it:www.instagram.com/api/v1/feed/saved/posts/with the web REST headers.Changes
instagram.feed_api = "web", default):_WebFeedon a temporarycopy_session()(main session unchanged), throughcontext.get_json(host="www.instagram.com")so instaloader's rate controller and error handling stay. Headers:X-IG-App-ID,X-ASBD-ID,X-CSRFToken(from thecsrftokencookie per request),X-IG-WWW-Claim(tracked fromx-ig-set-www-claim),X-Requested-With,Sec-Fetch-*, saved page asReferer;count=50,max_idpagination. The iPhone variant stays available (feed_api = "iphone")."fail": a feed page gets one attempt; onlyrequeststransport errors are retried (up tomax_connection_attempts). A"fail"answer raises the newInstagramFeedUnavailable(stop reasonfeed_unavailable, exit code 3, API job error code), saying the session is fine, nothing was lost, and whichfeed_apito try.config validatechecksfeed_api; docs (operations, configuration, CLI/API reference), CHANGELOG,config.example.toml.Test plan
uv run pytest: 1024 passed, 4 skipped (was 994/4); realInstaloaderContextwith fakedrequestsfor host/path/params/headers (CSRF from cookie, www-claim carried to page 2), web never touches thei.instagram.comfeed and vice versa, pagination/early stop/cursor loop/empty page/item shapes,"fail"= exactly one request + exit 3 + progress kept, network-error retries, config parsing, session console lines, runner/service mappingruff check,ruff format --check,mypy srccleanpostparse extract instagram --limit 1 --stop-after-known 1(2 requests) after mergeUpdate: no automatic password login (920c6c0)
Live test 22:24 from this branch: the session check said "not logged in", the collector logged in with the password automatically (third scripted password login of the day), and the first web feed page was answered with a confirmation request / login redirect. Decision: password logins are never automatic.
InstagramCollector(allow_password_login=False)by default: no session file / unreadable / logged out ->InstagramAuthRequired(exit 2) naming the reason andpostparse check instagram --login. Onlycheck instagram --login(interactive) passesTrue; extract, transcription re-fetches and API jobs forceFalse.login_required,checkpoint_required, redirect target as scheme+host+path) is shown in CLI and job errors; query strings, cookies and tokens are redacted, max 200 chars.max_id=...3429...no longer reads as HTTP 429).Update: verify after the password login, import the browser session (69792db)
Live tests 2026-10-27 20:07 and 22:16 from this branch: both stopped locally with "session file has no login cookies" (0 requests to Instagram, no password login). The user had run
check instagram --loginin between, which reported "session is valid" and saved a session withoutsessionid. Cause: instaloader 4.15.5's password login seeds empty placeholder cookies and reports success onauthenticated: trueeven when no realsessionidcomes back (instaloader#2487);--loginnever re-checked the new session.sessionid/ numericds_user_idraisesInstagramAuthRequiredwithout a request ("Instagram accepted the password but returned no session cookie (instaloader issue #2487); nothing was saved"), otherwise one session check runs. Nothing is saved on any failure; a throttled check after the login says so (InstagramSessionCheckFailed(after=...), exit 3).postparse check instagram --import-session: reads the browser'ssessionidcookie from a hidden prompt (csrftokenoptional, generated when empty), normalizes:to%3A, derivesds_user_id, verifies with exactly one request and saves only a confirmed session ofINSTAGRAM_USERNAME. Never uses the password; needs a TTY; mutually exclusive with--login. Values are never printed or logged (tests assert it; the sanitizer also redacts JSON-style and bare session ids).feed_api = "web":GET www.instagram.com/api/v1/users/<id>/info/with the same web headers as the feed (_WebFeed→ shared_WebClient), so a browser session is never sent with iPad headers toi.instagram.com.feed_api = "iphone"keepsget_iphone_json.--import-sessionfirst,--loginsecond.www.instagram.com/api/v1/users/<id>/info/answers likei.instagram.com, and that a browsersessionidwith a generatedcsrftokenis accepted.Update: web session check = first saved-feed page, reused by the walk (8e62e0c)
Live 2026-10-28 ~20:30: the user ran
check instagram --import-session; its only request,GET www.instagram.com/api/v1/users/<id>/info/, got429 Too Many Requests(~22 h after the previous Instagram request). Nothing was saved. The web app does not normally call that endpoint.feed_api = "web"the session check now requests the first page of the saved feed (api/v1/feed/saved/posts/, same params and web headers as the walk,Referer= the saved page) — the request the web app itself makes when the saved page is opened.extract instagram --limit 1 --stop-after-known 1with a valid session is exactly one request; later pages use itsmax_id. The import is one request too."fail"on the check raisesInstagramFeedUnavailable; an answer that is not a feed page raisesInstagramSessionCheckFailed; logout/checkpoint/throttle mapping unchanged. Nothing is saved on any failure.sessionidbelongs to (no username comparison);feed_api = "iphone"keeps theusers/<id>/info/check with the comparison.X-IG-WWW-Claimfrom the check's page on page 2.🤖 Generated with Claude Code